/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gazzopardi
 */
public class DAO {

    public static Collection<Dep> getLesDeps() {

        Collection<Dep> lesDeps = new TreeSet<Dep>();


        try {
            Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            ResultSet rs = req.executeQuery("select distinct departement from medecin;");

            while (rs.next()) {
                String dep = rs.getString("departement");
                Collection<Medecin> lesMeds = new TreeSet<Medecin>();
                
                Statement req2;
                req2 = con.createStatement();
                ResultSet rs2 = req2.executeQuery("select nom,prenom from medecin where departement = "+dep+"");
                while (rs2.next()) {
                    String nom = rs2.getString("nom");
                    String prenom = rs2.getString("prenom");
                    lesMeds.add(new Medecin(nom, prenom, null, null, null, null));

                }
                lesDeps.add(new Dep(dep, lesMeds));

            }






        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return lesDeps;

    }
}
